<template>
	<div>
		<el-descriptions class="margin-top" :title="dataItem.taskName" :column="2">
			<template #extra>
				<p>状态：{{ dataItem.status == 0 ? '开启' : '关闭' }}</p>
			</template>
			<el-descriptions-item label="隐患评估表">{{ dataItem.tableTemplateName }}</el-descriptions-item>
			<el-descriptions-item label="被评估对象">
				{{ [nowRowData.assessedFacility, nowRowData.assessedOrganizationName].toString() }}
			</el-descriptions-item>
			<el-descriptions-item label="评估第三方">{{ dataItem.evaluateThirdParties }}</el-descriptions-item>
			<el-descriptions-item label="有效时间">{{ dataItem.effectiveStartTime }}~{{ dataItem.effectiveEndTime }}</el-descriptions-item>
		</el-descriptions>

		<el-descriptions class="margin-top" :column="1">
			<template v-slot:title>
				<p>
					<span>任务进度（{{ dataItem.passing }}/{{ tableData.length }}）</span>
					<small>通过率：{{ dataItem.passingRate ? (dataItem.passingRate * 100).toFixed(2) : 0 }}%</small>
				</p>
			</template>
		</el-descriptions>
		<ApldTable :data="tableData" v-bind="tableConfig">
			<template v-slot:menu="{ row }">
				<el-button type="primary" text v-if="row.status == 1" @click="handleDetail(row)">查看评估表</el-button>
			</template>
		</ApldTable>

		<el-drawer append-to-body v-model="visible" title="评估详情" size="65%">
			<AccessDetail :nowRowData="accessRowData" />
		</el-drawer>
	</div>
</template>

<script setup lang="ts">
import apiMod from '@/apiMod/index'
import { ApldTable } from '@/components/AplidCrud'
import AccessDetail from '../../orgTask/AccessDetail/index.vue'
const props = defineProps<{
	nowRowData: any
}>()

const dataItem: any = ref({})
const visible = ref(false)
const tableData = ref([])
const accessRowData = ref({})
const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '被评估单位', prop: 'organizationName' },
		{ label: '提交时间', prop: 'evaluateTime' },
		{
			label: '状态',
			prop: 'status',
			custome: 'tag',
			dicData: [
				{
					label: '未评估',
					value: 0,
					type: 'info',
				},
				{
					label: '已评估',
					value: 1,
					type: 'success',
				},
			],
		},
		{
			label: '评估结果',
			prop: 'result',
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

const handleDetail = (row) => {
	accessRowData.value = row
	visible.value = true
}
const getInitData = () => {
	apiMod.view_pbHazardAssessmentTask_detail({ id: props.nowRowData.id }).then((res) => {
		dataItem.value = {
			...res.data,
			children: [],
		}
		if (res.data.children) {
			tableData.value = res.data.children.map((item) => {
				return {
					...item,
				}
			})
		}
	})
}

onMounted(() => {
	getInitData()
})
</script>

<style scoped></style>
